import { AxiosResponse } from 'axios';
import { api } from '../boot/axios';
import { ItemForm, StockItem } from './type';

function url(s: string) {
  return ['/api/stockitemtasks', s.replace('/', ''), ''].join('/');
}
export function getAllStockItemTasks() {
  return api({
    url: '/api/stockitemtasks/',
    method: 'get',
  });
}

export function deleteStockItemTask(id: number) {
  return api({
    url: url(`${id}`),
    method: 'delete',
  });
}

export function getStockItemTasks(stock_code: string) {
  return api({
    url: url('get_tasks'),
    method: 'post',
    data: { stock_code },
  });
}

export function getNestedStockItemTasks(stock_code: string) {
  return api({
    url: url('get_all_tasks'),
    method: 'post',
    data: { stock_code:stock_code.toUpperCase() },
  });
}

export function assignTask(data: {
  stock_item: number;
  name: string;
  eform_schema_id?: number;
}) {
  return api({
    url: '/api/stockitemtasks/',
    method: 'post',
    data: data,
  });
}

export function getCurStockItemTask(id: number) {
  return api({
    url: url(`${id}`),
    method: 'get',
  });
}

export function updateCurStockItemTask(
  id: number,
  data: {
    stock_item: number;
    name: string;
    eform_schema_id?: number;
  }
) {
  return api({
    url: url(`${id}`),
    method: 'patch',
    data: data,
  });
}
